<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport"
        content="width=device-width, minimum-scale=1, maximum-scale=1, user-scalable=no, initial-scale=1">
  <title>ai-clint</title>
  <!--<script src="http://cdn.staticfile.org/plupload/2.1.6/i18n/en.js"></script>-->
  <!--<script src="http://cdn.staticfile.org/qiniu-js-sdk/1.0.14-beta/qiniu.min.js"></script>-->
</head>
<body>
<script>

  function getQiNiuHost (key) {
    var EncodedMimeType = 'application/octet-stream';
    var url = 'http://upload.qiniu.com/putb64/-1/key/' + key;
    console.log(url);
    return url;
  }

  function qiNiuUploadBase64(accessToken, key, base64){
    var pic = base64;
    var url = this.getQiNiuHost(key);
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function(){
      if (xhr.readyState === 4){
        if (this.uploadBase64Callback){
          this.uploadBase64Callback(xhr.responseText);
        }
      }
    }.bind(this);
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/octet-stream");
    xhr.setRequestHeader("Authorization", "UpToken " + accessToken);
    xhr.send(pic);
  }

  this.uploadImageToQiNiu = function (accessToken, key, base64) {
    this.qiNiuUploadBase64(accessToken, key, base64);
  }

  function faceValidatorSuccess(base64){

    document.write(base64);
//    window.alert('收到人脸识别成功回调 base64:' + base64.substring(0, 50));
    if (this.userFaceCallback){
//      base64 = base64.replace(/<|>|\s/g, '');
      this.userFaceCallback(base64);
    }
  }

  function faceValidatorError(){
//    window.alert('收到人脸识别失败回调');
    if (this.userFaceCallback){
      this.userFaceCallback();
    }
  }

  this.getUserFace = function () {
    try{
      window.jsspdb.startFaceValidator();
    } catch(e) {
      window.alert('错误信息: ' + '\nmethodName=jsspdb.jumpToClientWithParentCode', e);
      if (window.userFaceCallback){
        window.userFaceCallback();
      }
    }
  }

  function doSomeThing () {
//    s = s.replace(/<|>|\s/g, '');
//    console.log(s);
//    setTimeout(function () {
//      window.jsspdb.startFaceValidator();
//    }, 5000);
  }
</script>

<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
